/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-05
 * Time: 15:22
 */
public class Homework {
    public int countSegments(String s) {
        /*if(s.equals("")) {
            return 0;
        }
        //用String[] split(String regex) ->装在一个字符串数组中
        String[] result = s.split(" ");
        int ret = result.length;
        return ret;*/
        if (s == null) {
            return 0;
        }

        int wordCount = 0;
        boolean inWord = false;

        for (int i = 0; i < s.length(); i++) {
            if (!Character.isWhitespace(s.charAt(i))) {
                if (!inWord) {
                    inWord = true;
                    wordCount++;
                }
            } else {
                inWord = false;
            }
        }
        return wordCount;
    }
    public static void main3(String[] args) {
        String s = "abcd ef";
        char ch1 = s.charAt(4);
        char ch2 = s.charAt(3);
        boolean ret1 = Character.isWhitespace(ch1);
        boolean ret2 = Character.isWhitespace(ch2);
        System.out.println(ret1);//true
        System.out.println(ret2);//false
    }
    public static void main2(String[] args) {
        String str = "hello world hello bit" ;
        String[] result = str.split(" ") ; // 按照空格拆分
        /*for(String s: result) {
            System.out.println(s);
        }*/
        int ret = result.length;
    }
    public static void main1(String[] args) {
        String s = "ABCDEF";
        String ss  = s.substring(1,5);
        System.out.println(ss);
        String sss = s.toLowerCase();
        System.out.println(sss);
    }

}
